﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp4
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "账号" || textBox2.Text == "密码")
            {
                MessageBox.Show("注册失败，请输入完整信息");
            }
            else 
            { 
            string sql = "insert into Student1(ID,pwd) values('"+textBox1.Text+"','"+textBox2.Text+"')";
            bool reader;
            reader = DBHelper.GetNonQuery(sql);
                MessageBox.Show("注册成功");
            }
        }

        private void textBox1_Enter(object sender, EventArgs e)
        {
            if(textBox1.Text=="账号")
            {
                textBox1.Text = "";
            }
        }

        private void textBox1_Leave(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                textBox1.Text = "账号";
            }
            else
            {
                SqlDataReader reader = null;
                string result = null;
                string sql = "select * from Student1 where ID='" + textBox1.Text + "'";
                reader = DBHelper.Select(sql);
                while (reader.Read())
                {
                    result = reader["ID"].ToString();
                }
                reader.Close();
                if (result == textBox1.Text)
                {
                    MessageBox.Show("该用户已存在，请重新输入");
                    textBox1.Text = "账号";
                }
            }
        }
        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox2_Enter(object sender, EventArgs e)
        {
            if (textBox2.Text == "密码")
            {
                textBox2.Text = "";
            }
        }

        private void textBox2_Leave(object sender, EventArgs e)
        {
            if (textBox2.Text == "")
            {
                textBox2.Text = "密码";
            }
            
        }
    }
}
